package com.fywsy.fyweb.strategy;

import com.fywsy.fyweb.entity.SendItem;
import com.fywsy.fyweb.utils.RestTemplateUtil;
import com.google.gson.Gson;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 游戏后台实现类
 * 注解gameId对应数据库游戏id
 * 注解GongnengMethod对应数据库功能id
 */
@Component
@GameId(16)
public class ADadongjiaGameStrategy extends BaseGameStrategy {

    public static final String URL = "http://110.40.83.167:30688/gm/gmaPay.php";


    /**
     * code: {"user_id":["701054400000001"],"title":"gm充值","content":"充值成功，请查收！","exTime":1440,"packge":[{"id":"4","num":"111","name":"名望"}],"groupId":100}
     * request_type: mail
     * userid: 701054400000001
     * @param item
     * @return
     */
    @GongnengMethod(1602)
    public String mail(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("request_type", "mail");
        params.add("userid", item.uid);
        Map<String,Object> code = new HashMap<>();
        code.put("user_id", item.uid);
        code.put("title", "GM Mail");
        code.put("content", "Welcome to FY");
        code.put("exTime", 144);
        code.put("groupId", 100);

        params.add("code","{\"user_id\":[\"" + item.uid + "\"],\"title\":\"gmMail\",\"content\":\"Fy666\",\"exTime\":1440,\"packge\":[{\"id\":\"" + item.itemId + "\",\"num\":\"" + item.number + "\"}],\"groupId\":100}");
        String s = RestTemplateUtil.sendPostFormAndGetJsonKey(URL, params, "message");
        return s;
    }

    /**
     * request_type: daijin
     * userid: 701054400000001
     * code: {"playerId":"701054400000001","num":"122222","type":0}
     * @param item
     * @return
     */
    @GongnengMethod(1601)
    public String pay(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("request_type", "daijin");
        params.add("userid", item.uid);
        Map<String,String> code = new HashMap<>();
        code.put("playerId", item.uid);
        code.put("num", item.number);
        code.put("type", "0");
        params.add("code",new Gson().toJson(code));
        String s = RestTemplateUtil.sendPostFormAndGetJsonKey(URL, params, "message");
        return s;
    }

    @GongnengMethod(1603)
    public String day(SendItem item) {
        return mail(item);
    }

    @GongnengMethod(4)
    public String cleat(SendItem item) {
        System.out.println("清除成功");
        return "清除成功";
    }


    public static void main(String[] args) {
        SendItem item = new SendItem();
        item.number ="400";
        item.uid = "701054400000001";
        item.itemId = "4";
//        String pay = new ADadongjiaGameStrategy().pay(item);
        String pay = new ADadongjiaGameStrategy().mail(item);
        System.out.println(pay);
    }
}

